<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/static/weui/css/weui.css"/>
    <link rel="stylesheet" href="/static/weui/css/weuix.css"/>

    <script src="/static/weui/js/zepto.min.js"></script>
    <script src="/static/weui/js/zepto.weui.js"></script>
    <script>

        var p_a = [];
        var s_a = [];
        var d_a = [];
        var j_a = [];
        var t_a = [];
        var click_sign = true;

        $(function () {
            $(document).on("click", "#btn", function () {
                if(!click_sign){
                    $.toptip("数据提交中...", 'success');
                    return false;
                }
                click_sign = false;

                $.ajax({
                    url:"",    //请求的url地址
                    dataType:"json",   //返回格式为json
                    async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data:{danxuan: s_a, duoxuan: d_a,panduan:p_a,jianda:j_a,tiankong:t_a},    //参数值
                    type:"post",   //请求方式
                    beforeSend:function(){
                        //请求前的处理
                    },
                    success:function(res){
                        //请求成功时处理
                        if (res.code == 200) {
                            click_sign = true;
                            $.toptip("提交成功", 'success');
                            window.location.href = "{:url('/mobile/index/score')}?score=" + res.data;
                        } else {

                            $.toptip(res.msg);
                        }
                    },
                    complete:function(){
                        //请求完成的处理
                    },
                    error:function(){
                        //请求出错处理

                        $.toptip('网络错误，稍后重试');
                    }
                });

            })
            //解决表单控件不能回弹 只有微信ios有这个问题
            $("input,select,textarea").blur(function () {
                setTimeout(() => {
                    const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
                    window.scrollTo(0, Math.max(scrollHeight - 1, 0));
                }, 100);
            })

        });

        function panduan(qid,content) {
            var sign = true;
            for(var i=0;i<p_a.length;i++){
                if(p_a[i]['qid']==qid){
                    p_a[i]['answer'] = content;
                    sign = false;
                    break;
                }
            }
            if(sign){
                p_a.push({qid:qid,answer:content});
            }
        }


        function radio(qid,content) {
            var sign = true;
            for(var i=0;i<s_a.length;i++){
                if(s_a[i]['qid']==qid){
                    s_a[i]['answer'] = content;
                    sign = false;
                    break;
                }
            }
            if(sign){
                s_a.push({qid:qid,answer:content});
            }
        }

        function checkbox(qid,content) {
            var sign = true;

            for(var i=0;i<d_a.length;i++){
                if(d_a[i]['qid']==qid){
                    for(var j=0;j<d_a[i].answer.length;j++){
                        if(d_a[i].answer[j]==content){
                            d_a[i].answer.splice(j,1);
                            return false;
                        }
                    }
                    d_a[i].answer.push(content);
                    sign = false;
                    break;
                }
            }
            if(sign){
                var answer = [];
                answer.push(content);
                d_a.push({qid:qid,answer:answer});
            }
            console.log(d_a);
        }

function tiankong(qid,cla) {
    var sign = true;
    for(var i=0;i<t_a.length;i++){
        if(t_a[i]['qid']==qid){
            t_a[i]['answer'] = $("#tk"+cla).val();
            sign = false;
            break;
        }
    }
    if(sign){
        t_a.push({qid:qid,answer:$("#tk"+cla).val()});
    }
}

function jianda(qid,cla) {
    var sign = true;
    for(var i=0;i<j_a.length;i++){
        if(j_a[i]['qid']==qid){
            j_a[i]['answer'] = $("#jd"+cla).val();
            sign = false;
            break;
        }
    }
    if(sign){
        j_a.push({qid:qid,answer:$("#jd"+cla).val()});
    }
}

        function cleartxt(obj) {
            $(obj).prev().find('.weui-input').val("");
            return false;
        }


    </script>
    <style>
        img{
            max-width: 100%;
        }
        .weui-cells__title{
            font-size: 16px;
            color: #333333;
            display: flex;
            align-items: center;
        }
        .weui-cells__title img{
            max-width: 100%;
        }
        .weui-cell__bd{
            font-size: 14px;
            color: #666666;
        }
        .weui-cells_checkbox .weui-icon-checked::before{
            font-size: 14px;
        }
        .weui-cells_checkbox  {
            margin-bottom: 5px;
        }
        .weui-check__label  {
            vertical-align: middle;
        }
        .weui-cell__bd p{
            display: flex;
            align-items: center;
            vertical-align: center;
        }
    </style>
</head>

<body ontouchstart>
{php} if($active){ {/php}
<div class="page-hd">
    <h1 class="page-hd-title" style="text-align: center">
        {$active['name']}
    </h1>
    <p class="page-hd-desc"></p>
</div>


<div class="weui-cells weui-cells_form">


    {php} if(!empty($q1)){ {/php}
             <div class="q1">

                 <h3>一、判断题</h3>
                 {php} foreach($q1 as $k =>$val){ {/php}

                 {php} if($val['q_type']==1){ {/php}
                 <div class="weui-cells__title">{:$k+1}. {:$val['name']}</div>
                 {php} }else{ {/php}
                 <div class="weui-cells__title"><span>{:$k+1}. </span><img src="{$val['name']}" alt=""></div>
                 {php} }{/php}

                 <input name="sw{:$k+1}" value="{:$val['id']}" type="hidden" >
                 <div class="weui-cells weui-cells_checkbox">
                     {php} foreach($val['answer_arr'] as $key => $value){  {/php}
                     {php}$content=$value['content'];{/php}
                     <label class="weui-cell weui-check__label" for="p{:$k}{:$key}" >
                         <div class="weui-cell__hd">
                             <input onclick='panduan({$val["id"]},this.value)' class="weui-check" name="p{:$k+1}" id="p{:$k}{:$key}" value="{$value['content']}"  type="radio" >
                             <i class="weui-icon-checked"></i>
                         </div>
                         <div class="weui-cell__bd">
                             {php} if($val['q_type']==1){ {/php}
                             <p>{$value['sign']}、{$value['content']}</p>
                             {php} }else{ {/php}
                             <p><span>{$value['sign']}、</span><img src="{$value['content']}" alt=""></p>
                             {php} }{/php}
                         </div>
                     </label>
                     {php}}{/php}
                 </div>
                 {php}}{/php}
             </div>


    {php} } {/php}


    {php} if(!empty($q2)){ {/php}
    <div class="q1">
        {php} if(!empty($q1)){ {/php}
        <h3>二、单选题</h3>
        {php} }else{ {/php}
        <h3>一、单选题</h3>
        {php} }{/php}
        {php} foreach($q2 as $k =>$val){ {/php}
        {php} if($val['q_type']==1){ {/php}
        <div class="weui-cells__title">{:$k+1}. {:$val['name']}</div>
        {php} }else{ {/php}
        <div class="weui-cells__title">{:$k+1}. <img src="{$val['name']}" alt=""></div>
        {php} }{/php}

        <input name="sw{:$k+1}" value="{:$val['id']}" type="hidden" >
        <div class="weui-cells weui-cells_checkbox">
            {php} foreach($val['answer_arr'] as $key => $value){  {/php}
            {php}$content=$value['content'];{/php}
            <label class="weui-cell weui-check__label" for="s{:$k}{:$key}" >
                <div class="weui-cell__hd">
                    <input onclick='radio({$val["id"]},this.value)' class="weui-check" name="a{:$k+1}" id="s{:$k}{:$key}" value="{$value['content']}"  type="radio" >
                    <i class="weui-icon-checked"></i>
                </div>
                <div class="weui-cell__bd">
                    {php} if($val['q_type']==1){ {/php}
                    <p>{$value['sign']}、{$value['content']}</p>
                    {php} }else{ {/php}
                    <p><span>{$value['sign']}、</span><img src="{$value['content']}" alt=""></p>
                    {php} }{/php}
                </div>
            </label>
            {php}}{/php}
        </div>
        {php}}{/php}
    </div>
    {php} } {/php}

    {php} if(!empty($q3)){ {/php}
    <div class="q2">

        {php} if(!empty($q1)){ {/php}
        {php} if(!empty($q2)){ {/php}
        <h3>三、多选题</h3>
        {php} }else{ {/php}
        <h3>二、多选题</h3>
        {php} }{/php}
        {php} }else{ {/php}
        {php} if(!empty($q2)){ {/php}
        <h3>二、多选题</h3>
        {php} }else{ {/php}
        <h3>一、多选题</h3>
        {php} }}{/php}
        {php} foreach($q3 as $k =>$val){ {/php}
        {php} if($val['q_type']==1){ {/php}
        <div class="weui-cells__title">{:$k+1}. {:$val['name']}</div>
        {php} }else{ {/php}
        <div class="weui-cells__title">{:$k+1}. <img src="{$val['name']}" alt=""></div>
        {php} }{/php}
        <input name="dw{:$k+1}" value="$val['id']" type="hidden" >
        <div class="weui-cells weui-cells_checkbox">
            {php} foreach($val['answer_arr'] as $key => $value){ {/php}
            <label class="weui-cell weui-check__label" for="d{:$k}{:$key}" >
                <div class="weui-cell__hd">
                    <input class="weui-check" onclick='checkbox({$val["id"]},this.value)'  name="d{:$k+1}" id="d{:$k}{:$key}" value="{$value['content']}"  type="checkbox" >
                    <i class="weui-icon-checked"></i>
                </div>
                <div class="weui-cell__bd">
                    {php} if($val['q_type']==1){ {/php}
                    <p>{$value['sign']}、{$value['content']}</p>
                    {php} }else{ {/php}
                    <p><span>{$value['sign']}、</span><img src="{$value['content']}" alt=""></p>
                    {php} }{/php}
                </div>
            </label>
            {php}}{/php}
        </div>
        {php}}{/php}
    </div>
    {php} } {/php}

    {php} if(!empty($q4)){ {/php}
    <div class="q3">
        {php} if($count==4){ {/php}
        <h3>四、简答题</h3>
        {php} }else if($count==3){ {/php}
        <h3>三、简答题</h3>
        {php} }else if($count==2){ {/php}
        <h3>二、简答题</h3>
        {php} }else{ {/php}
        <h3>一、简答题</h3>
        {php} } {/php}



        {php} foreach($q4 as $k =>$val){ {/php}
        <div class="weui-cells__title">{:$k+1}. {:$val['name']}</div>
        <input name="jd{:$k+1}" value="$val['id']" type="hidden" >
        <textarea style="width: 90%;margin: 0 5%" onchange="jianda({$val['id']},{$k})" name="jd{:$k+1}" id="jd{:$k}" cols="40" rows="15" placeholder="请将答案填写到框内"></textarea>
        {php}}{/php}
    </div>

    {php} } {/php}

    {php} if(!empty($q5)){ {/php}
    <div class="q5">

        {php} if($count==5){ {/php}
        <h3>五、填空题</h3>
        {php} }else if($count==4){ {/php}
        <h3>四、填空题</h3>
        {php} }else if($count==3){ {/php}
        <h3>三、填空题</h3>
        {php} }else if($count==2){ {/php}
        <h3>二、填空题</h3>
        {php} }else{ {/php}
        <h3>一、填空题</h3>
        {php} } {/php}



        {php} foreach($q5 as $k =>$val){ {/php}

        {php} if($val['q_type']==1){ {/php}
        <div class="weui-cells__title">{:$k+1}. {:$val['name']}</div>
        {php} }else{ {/php}
        <div class="weui-cells__title">{:$k+1}. <img src="{$val['name']}" alt=""></div>
        {php} } {/php}
        <input name="tk{:$k+1}" value="$val['id']" type="hidden" >
        <input style="width: 90%;margin: 0 5%;height: 24px" onchange="tiankong({$val['id']},{$k})" name="tk{:$k+1}" id="tk{:$k}" placeholder="请将答案填写到框内"/>
        {php}}{/php}
    </div>

    {php} } {/php}


</div>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="btn">提交</a>
</div>
{php}}else{{/php}

<div class="weui-msgbox" id="s3">
    <p>
        <i class="weui-icon-info-circle"></i>
        {php} if(isset($msg)){ {/php}
        {$msg}
        {php} }else{  {/php}
        暂无数据
        {php} } {/php}
    </p>
</div>

{php}}{/php}




<br>
<br>

<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__text">Copyright &copy; 上海工商职业技术学院</p>
</div>
</body>
</html>